import com.dmotiko.general.*
import com.dmotiko.util.*
import mx.utils.Delegate;

class com.dmotiko.general.WebSiteSection
extends BaseClip {
	
	public static var SHOW_END:String = "websitesection_showend";
	public static var HIDE_END:String = "websitesection_hideend";
		
	private var sName:String;
	private var bShowed:Boolean;
			
	private function WebSiteSection(app) {
		super();
		setData(app);
		app.addEventListener( WebSite.SECTION_CHANGED, Delegate.create(this, sectionChanged) );
	}
	
	private function sectionChanged(evnt) {
		if( !getData() || getData().getSection() == sName) {
			/*
			if ( WebSite(data).getActiveSection() && WebSite(data).getActiveSection() != this ) {
				WebSite(data).getActiveSection().addEventListener( WebSiteSection.HIDE_END, Delegate.create(this, showSection), WebSiteSection.HIDE_END);
			} else {
				showSection();
			}
			*/
			showSection();
		} else {
			hideSection();
		}
	}
		
	public function showSection() {
		if (bShowed) return;
		bShowed = true;
		this._visible = true;
		showEnd();
	}
	
	public function hideSection() {
		if (!bShowed) return;
		this._visible = false;
		bShowed = false;
		hideEnd();
	}
	
	private function showEnd() {
		dispatchEvent( { target: this, type: SHOW_END } );
	}
	
	private function hideEnd() {
		dispatchEvent( { target: this, type: HIDE_END } );
	}
	
	public function getName():String { return sName; }
	
}